package com.wisemoresystem.seal.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.ne.framework.data.page.Page;
import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wisemoresystem.seal.base.service.BaseService;
import com.wisemoresystem.seal.util.DateTools;

@Service
public class SealTransRightService extends BaseService {
	@Autowired
	private BankService service;
	
	public List<Map<String, Object>> selectSealTransRightList(String srh_uname,
			String srh_name, String srh_start, String srh_end, Page page) {
		String ids = service.selectUbank2();
		if(ChkTools.isNull(ids)){
			ids = "''";
		}
		String sql = "select t.*, tu.uname begin_user,tus.uname end_user,tb.name bank_name "
				+ " from t_seal_auth t "
				+ " left join t_user tu on t.begin_user_id=tu._id "
				+ " left join t_user tus on t.end_user_id=tus._id "
				+ " left join t_bank tb on t.bank_id=tb._id "
				+ " where t.status=0 and tb._id in (@ids) and tb.name like ? and tu.uname like ? "
				+ " and t.created>=? and t.created<=? "
				+ " order by t.created desc";
		List<String> params = new ArrayList<String>();
		if (ChkTools.isNull(srh_uname)) {
			sql = sql.replace("and tb.name like ?", "");
		} else {
			params.add("%" + srh_uname + "%");
		}
		if (ChkTools.isNull(srh_name)) {
			sql = sql.replace("and tu.uname like ?", "");
		} else {
			params.add("%" + srh_name + "%");
		}
		if (ChkTools.isNull(srh_start)) {
			sql = sql.replace("and t.created>=? and t.created<=?", "");
		} else {
			params.add(srh_start);
			params.add(DateTools.addOneDay(srh_end));
		}
		sql = sql.replace("@ids", ids);
		List<Map<String, Object>> list = jc.queryForList(sql, params.toArray(),
				page);
		return list;
	}
	
}
